package com.lixin.demo.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.lixin.demo.entity.Account;
import com.lixin.demo.mapper.AccountMapper;
import com.lixin.demo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountMapper accountMapper;

    @Override
    public int reduceBalance(Long id, float balance) {
        Account account = accountMapper.getAccountById(id);
        balance = account.getBalance() - balance;
        if (balance < 0) return 0;
        return accountMapper.updateAccountBalance(id, balance);
    }

}
